<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCommentsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('comments', function (Blueprint $table) {
            $table->increments('id');
            $table->char('key', 36)->comment('唯一码')->unique();
            $table->string('request_id', 36)->index();
            $table->integer('uid')->comment('用户ID')->index();
            $table->integer('tid')->comment('帖子ID')->index();
            $table->integer('pid')->default(0)->comment('父级评论ID')->index();
            $table->integer('root_id')->default(0)->comment('一级评论ID，只有楼中楼才有')->index();
            $table->integer('floor_num')->default(-1)->comment('楼层号，正常楼层才有')->index();
            $table->integer('is_main_floor')->default(0)->comment('是否主楼');
            $table->string('detail_excerpt')->default('')->comment('详情摘要');

            $table->integer('comment_count')->default(0)->comment('评论数')->index();
            $table->integer('like_count')->default(0)->comment('被顶数')->index();
            $table->integer('dislike_count')->default(0)->comment('被踩数');
            $table->integer('favor_count')->default(0)->comment('收藏数');
            $table->timestamps();
            $table->softDeletes();

        });
        \DB::statement("ALTER TABLE `comments` comment '评论表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('comments');
    }
}
